export default {
  namespaced:true,
  state(){   //此处的state，相当于组件中的data，存放可跨组件同步共享的数据
    return {
      goods:[
        {name:'1号商品',price:1999,n:4},
        {name:'2号商品',price:199.9,n:2},
        {name:'3号商品',price:19.99,n:1},
        {name:'4号商品',price:1.999,n:4},
      ]
    }
  },
  getters:{ //相当于组件中的computed，会根据state动态生成新数据
    filterGoods(state){
      return state.goods.filter(item=>{
        return item.price>500
      })
    }
  },
  mutations:{  //唯一可以触发state变化的方法集
    goodsAddMut(state,goodsObj){
      state.goods.push(goodsObj)
    }
  }
}